<?php namespace App\Services;

use App\Facades\Infra\CommodityManager;

class CommodityService{

	public function addType($data){
		CommodityManager::addType($data);
	}

	public function getType($id){

		return CommodityManager::getType($id);
	}

	public function getTypes(){
		return CommodityManager::getTypes(null,$first = true)->paginate(10);
	}

	public function updateType($id,$data){
		return CommodityManager::updateType($id,$data);
	}

	public function deleteType($id){
		return CommodityManager::deleteType($id);
	}

	public function addCommodity($data){
		$data['c_picture'] = json_encode($data['c_picture']);

		CommodityManager::addCommodity($data);
	}

	public function getCommodities($conditions){
		return CommodityManager::getCommodities($conditions,$first = true)->paginate(10);
	}

	public function getCommodity($id){
		return CommodityManager::getCommodity($id);
	}

	public function updateCommodity($data){
		$id = $data['id'];

		$data['c_picture'] = json_encode($data['c_picture']);

		CommodityManager::updateCommodity($id,$data);
	}

	public function deleteCommodity($id){
		CommodityManager::deleteCommodity($id);
	}
}